﻿using Cms.Application.Admin.Views;
using Cms.Data;
using Cms.Domain;
using Cms.Domain.RepositoryInterfaces;

namespace Cms.Application.Admin.Presenters
{
    public class UploadPresenter : BasePresenter
    {
        private readonly Administrator _administrator;
        private readonly IUploadView _view;

        public UploadPresenter(IUploadView view)
            : this(view, new RepositoryFactory())
        {
        }

        public UploadPresenter(IUploadView view, IRepositoryFactory repositoryFactory)
            : base(view, repositoryFactory)
        {
            _view = view;
            _administrator = AdministratorRepository.GetAdministrator(_view.AdministratorID);
            MediaFolder folder = MediaRepository.GetMediaFolder(_administrator.SelectedMediaFolderID);
            _view.SetFolderName(folder != null ? folder.GetVirtualPath() : _administrator.CurrentSite.RootMediaFolder);
            if (!_administrator.HasPermission.Upload)
                _view.RedirectToPermissionDeniedPage();
        }
    }
}